package service

import (
	"log"
	"time"
)

func SetupTimer() {
	var Second1 = 1
	var Second2 = 3
	RefreshTimer1 := time.NewTimer(time.Duration(Second1) * time.Second)
	RefreshTimer2 := time.NewTimer(time.Duration(Second2) * time.Second)

	//循环监听定时器
	go func() {
		for {
			select {
			case <-RefreshTimer1.C:
				//队列缓存
				if err := NewStoreQueueService().RefreshTmpList(); err != nil {
					log.Println("RefreshTmpList：定时任务出错：", err.Error())
					return
				}

				//超时后重置定时器需要跟上面RefreshTimer1设置的时间一样
				RefreshTimer1.Reset(time.Duration(Second1) * time.Second)

			case <-RefreshTimer2.C:
				if err := NewStoreQueueService().RefreshWork(); err != nil {
					log.Println("RefreshWork：定时任务出错：", err.Error())
				}
				//超时后重置定时器 1秒执行一次
				RefreshTimer2.Reset(time.Duration(Second2) * time.Second)
			}
		}
	}()
}
